class Watcher {
    constructor() {
      this.data = {};
    }
  
    // 定义属性访问器，并添加变化监听
    watchProperty(key) {
      let value = this.data[key];
  
      Object.defineProperty(this.data, key, {
        get() {
          return value;
        },
        set(newValue) {
          if (newValue !== value) {
            console.log(`Property ${key} changed from ${value} to ${newValue}`);
            value = newValue;
          }
        },
      });
    }
  }
  
  // 测试
  const watcher = new Watcher();
  watcher.watchProperty('name');
  
  watcher.data.name = 'Alice'; // Property name changed from undefined to Alice
  watcher.data.name = 'Bob';   // Property name changed from Alice to Bob